package cn.itlaobing.dao;

import cn.itlaobing.model.UserModel;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * Created by xuaner on 2017/11/6.
 */
public class UserDao extends BaseDao {
    public UserModel findByUserName(String user_name)throws SQLException{
        QueryRunner qr=new QueryRunner(getDataSource());
        String sql="select * from userinfo where user_name=? or tel=?";
        BeanHandler<UserModel> userModelBeanHandler=new BeanHandler<UserModel>(UserModel.class);
        return qr.query(sql,userModelBeanHandler,user_name,user_name);
    }
    /**
     * 更新时间为当前时间
     *
     * */
    public void updateTime(int id)throws SQLException{
        QueryRunner qr=new QueryRunner(getDataSource());
        String sql="update userinfo set near_time=now() where user_id=?";
        qr.update(sql,id);
    }
}
